﻿using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using SmlEngine.Graphics;

namespace SmlEngine.Sprites.Components
{
    public class AnimationComponent : SpriteComponent
    {
        private AnimationPlayer player;

        #region Properties

        public AnimationPlayer Player
        {
            get { return player; }
        }

        public SpriteEffects SpriteEffects { get; set; }

        public Dictionary<string, Animation> Animations { get; private set; }

        #endregion

        public AnimationComponent(Sprite sprite)
            : this(sprite, SpriteEffects.None) { }

        public AnimationComponent(Sprite sprite, SpriteEffects spriteEffects)
            : base(sprite)
        {
            player = new AnimationPlayer();
            Animations = new Dictionary<string, Animation>();
            SpriteEffects = spriteEffects;
        }

        public void PlayAnimation(string name)
        {
            if (Animations.ContainsKey(name))
                player.PlayAnimation(Animations[name]);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            player.Draw(gameTime, spriteBatch, Owner.Position, SpriteEffects);
        }
    }
}
